<div class="layui-fluid" id="add">
    <form class="layui-form" action="" lay-filter="teacherProject-add-form">

        <div class="layui-form-item">
            <label class="layui-form-label">班级：</label>
            <div class="layui-input-block">
                <select name="deptId" lay-verify="">
                    <option value="">请选择一个班级</option>
                    <div th:each="dept : ${depts}">
                        <option th:value=${dept.deptId}><span th:text=${dept.deptName}></span></option>
                    </div>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">项目：</label>
            <div class="layui-input-block">
                <select name="projectId"
                        lay-verify="required"
                        xm-select-direction="down"
                        xm-select="teacher-update-project"
                        xm-select-skin="default">
                </select>
            </div>
        </div>

        <div class="layui-form-item febs-hide">
            <button class="layui-btn" lay-submit="" lay-filter="teacherProject-add-form-submit" id="submit"></button>
            <button type="reset" class="layui-btn" id="reset"></button>
        </div>
    </form>
</div>

<script>
    layui.use(['febs', 'form', 'validate','formSelects', 'eleTree'], function () {
        var $ = layui.$,
            febs = layui.febs,
            layer = layui.layer,
            eleTree = layui.eleTree,
            form = layui.form,
            formSelects = layui.formSelects,
            $view = $('#add'),
            validate = layui.validate,
            className,
            projectName,
            _deptTree;

        form.verify(validate);
        form.render();

        formSelects.config('teacher-update-project', {
            searchUrl: ctx + 'teacherProject/getAllTeacherProject',
            response: {
                statusCode: 200
            },
            beforeSuccess: function (id, url, searchVal, result) {
                var data = result.data;
                var tranData = [];
                for (var i = 0; i < data.length; i++) {
                    tranData.push({
                        name: data[i].projectName,
                        value: data[i].projectId
                    })
                }
                result.data = tranData;
                return result;
            },
            error: function (id, url, searchVal, err) {
                console.error(err);
                febs.alert.error('获取角色列表失败');
            }
        });
        form.on('submit(teacherProject-add-form-submit)', function (data) {
            /*data.field.deptIds = deptIds;
            data.field.deptNameLists = deptNames;
            data.field.courseContent = editor.txt.text();*/
            febs.post(ctx + 'teacherProject/add', data.field, function () {
                layer.closeAll();
                $('#febs-user').find('#query').click();
            });
            return false;
        });
    });
</script>